<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      // 冒泡排序方法
      function bubbleSort(array) {
        for (i = array.length - 1; i >= 0; i--) {
          for (j = 0; j <= array.length; j++) {
            if (array[j] > array[j + 1]) {
              let temp = array[j + 1];
              array[j + 1] = array[j];
              array[j] = temp;
            }
          }
        }
        return array;
      }

      let arr = [4, 6, 7, 2, 4, 7, 9, 5];
      console.log(bubbleSort(arr));
    </script>
  </body>
</html>
